var app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({
    data: {
        bklength: '',
        indexTime: 0,
        bkList: [],
        timeOptions: {},// 每个职业对应的开班时间选项
        items: [
            { value: 0, name: '理论' },
            { value: 1, name: '实操', },
            { value: 2, name: '综合' },
        ],
        itemsData: [],
        major: '',
        updateId: '',
        status: '',
        timedate: '', //  报考时间
        peType: 10000, //人员类别
        sbKemu: 10000,//申报科目
        minDate: new Date(2024, 0, 1).getTime(),
        maxDate: new Date(2024, 2, 31).getTime(),
        fileList: [], //上传毕业证
        zhengshuList: [], // 证书列表
        gongzuoList: [],//工作经历
        occupation: '', // 申报职业
        careerYears: '', // 职业年限
        show: false, // 日历组件显示隐藏
        workUnit: '', //工作单位
        sfznumber: '',// 身份证号
        sfzaddress: '', // 身份证
        radioList: [
            { value: 0, name: '学生' },
            { value: 1, name: '企业员工', },
            { value: 2, name: '社会人员' },
        ], // 单选框选择
        kemuradioList: [
            { value: 0, name: '理论' },
            { value: 1, name: '实操', },
            { value: 2, name: '综合' },
        ], // 申报科目单选框选择
        isSign: false,//是否签名
        loginModal: false,
        isLogin: true, //是否登录
        name: '',
        idCard: '',
        schoolName: '',
        mobile: '',
        state: '', //（0待审核，1待缴费，2未通过，3已分配，4已缴费，9已删除
        OrgName: '',//工作单位
        unitPhone: '',//单位联系电话
        postName: '',//岗位名称
        index: 0,
        orgId: '',
        phoneNum: '',
        // mobile: '',//电话号码
        certificateNo: '',//毕业证书编号
        levelNum: '',//原证书编号
        address: '',//邮寄地址
        declarationPeriod: '',//累计从事申报职业年限
        images: '/image/touxiang.png',
        imagesXueli: '/image/addPic.png',
        recordCertificate: '/image/addPic.png', //学历证书 
        imagesWork: '/image/addPic.png',
        kemu: [],
        workProve: '', //工作证明
        idFront: '/image/addPic.png', //身份证正面
        imagesFront: '/image/addPic.png',
        idReverse: '/image/addPic.png', //身份证反面
        imagesReverse: '/image/addPic.png',
        typeList: [{
            id: '',
            name: '请选择考生类型'
        }, {
            id: 0,
            name: '在校考生'
        }, {
            id: 1,
            name: '社会考生'
        }],
        genre: [{
            id: null,
            name: '请选择认定类型'
        },
        {
            id: 0,
            name: '正考'
        },
        {
            id: 1,
            name: '补考'
        }],
        index: 0,
        sexList: [{
            id: 0,
            name: '请选择性别'
        }, {
            id: 1,
            name: '男'
        }, {
            id: 2,
            name: '女'
        }],
        indexSex: 0,
        educationList: ["请选择学历", '初中', '高中', '中专', '大专', '大学', '硕士', '博士'], //学历
        indexEducation: 0,
        education: '', //学历
        indexProfile: 0,
        birthTime: '',
        
        workDate: '',
        //experience:'',
        // dateWork:'',//参加工作时间
        classLevel: '',//原职业等级
        indexKpoints: 0,
        alreadyModal: false,
        gradeList: ["请选择类型", '三级', '四级', '五级'],
        professionList: [],
        indexNation: 0, //申报职业index
        indexDeclarationLevel: 0,
        indexProfession: 0,
        isProfession: false,
        isNation: false,
        isDeclarationLevel: false,
        isEducation: false,
        declarationLevel: '',//申报认定等级
        profession: '',//申报认定职业
        region: [],
        newsList: [],
        typeIndex: 0,
        type: '',
        inputShowed: false,
        inputVal: "",
        bookList: [], // 证书列表
        workjlList: [], // 工作经历
        a: true,//选中机构后取消下拉框
        list: [{ id: 0, name: '理论' },
        { id: 1, name: '实操' }
        ],
        datalist: {},
        reason: '',// 拒绝原因
        hcdatalist: {},
        active: '',
        bmList: [],
        indexbm: '',
    },
    onLoad: function (options) {
        let token = wx.getStorageSync('token')
        if (!token) {
            app.doLogin()
            return false;
        }else{
            this.handleGetBkTime()
        this.handleGetUserInfo()
        }
        // if (wx.getStorageSync('certificateInfo').certificateName == '育婴师') {
        //     this.setData({
        //         indexNation: 0,
        //     })
        // }
        // if (wx.getStorageSync('certificateInfo').certificateName == '保育师') {
        //     this.setData({
        //         indexNation: 1,
        //     })
        // }
        // if (wx.getStorageSync('certificateInfo').certificateName == '养老护理员') {
        //     this.setData({
        //         indexNation: 2,
        //     })
        // }
        
        // console.log(wx.getStorageSync('certificateInfo').open_time.split(',').length, 'length');
        // if (wx.getStorageSync('certificateInfo').open_time.split('，').length == 1) {
        //     this.setData({
        //         bklength: wx.getStorageSync('certificateInfo').open_time.split(',').length,
        //         timedate: wx.getStorageSync('certificateInfo').open_time
        //     })
        // } else {
        //     this.setData({
        //         bkList: wx.getStorageSync('certificateInfo').open_time.split('，').reverse(),
        //     })
        // }
        // this.setData({
        //     maxDate: new Date((wx.getStorageSync('certificateInfo')).endTime.split(' ')[0]).getTime(),
        //     minDate: new Date((wx.getStorageSync('certificateInfo')).startTime.split(' ')[0]).getTime()
        // })

        this.setData({
            type: options.type,
            datalist: JSON.parse(options.datalist),
            updateId: JSON.parse(options.datalist).id
        })
        this.setData({
            id: options.id, //认证批次id
            grade: wx.getStorageSync('certificateInfo').grade
        })
        var time = util.formatTime(new Date());
        this.setData({
            nowDate: time.substring(0, 10),
        })
        this.handleGetDataList()
        this.setData({
            status: wx.getStorageSync('status'),
        })
    },
    onShow: function (options) {
        this.setData({
            type: options.type,
            datalist: JSON.parse(options.datalist)
        })
        this.handleGetBkTime()
        this.handleGetUserInfo()
        if (wx.getStorageSync('hcdatalist')) {
            this.setData({
                status: wx.getStorageSync('hcdatalist').status,
                name: wx.getStorageSync('hcdatalist').name,
                mobile: wx.getStorageSync('hcdatalist').mobile,
                indexSex: wx.getStorageSync('hcdatalist').sex,
                birthTime: wx.getStorageSync('hcdatalist').born,
                indexEducation: wx.getStorageSync('hcdatalist').education,
                major: wx.getStorageSync('hcdatalist').major,
                peType: wx.getStorageSync('hcdatalist').personType,
                certificateType: '0',
                sfzaddress: wx.getStorageSync('hcdatalist').idcardAddress,
                sfznumber: wx.getStorageSync('hcdatalist').idcardNumber,
                workUnit: wx.getStorageSync('hcdatalist').workUnit,
                timedate: wx.getStorageSync('hcdatalist').examTime,
                careerYears: wx.getStorageSync('hcdatalist').workTime,
                indexNation: Number(wx.getStorageSync('hcdatalist').declaredCareers),
                occupation:wx.getStorageSync('hcdatalist').occupation,
                indexDeclarationLevel: wx.getStorageSync('hcdatalist').declaredLevel,
                // sbKemu: wx.getStorageSync('hcdatalist').declaredSubject,
                itemsData: wx.getStorageSync('hcdatalist').declaredSubject.split(','),
                idFront: wx.getStorageSync('hcdatalist').personPhoto,
                idReverse: wx.getStorageSync('hcdatalist').idcardPhoto,
                imagesFront: wx.getStorageSync('hcdatalist').personPhoto,
                imagesReverse: wx.getStorageSync('hcdatalist').idcardPhoto,
                recordCertificate: wx.getStorageSync('hcdatalist').graducationPhoto,
                imagesXueli: wx.getStorageSync('hcdatalist').graducationPhoto,
                updateId: wx.getStorageSync('hcdatalist').id
            })
        }

        var _this = this
        //获取签名路径
        if (wx.getStorageSync('signSrc') != null) {
            _this.setData({
                signSrc: wx.getStorageSync('signSrc'),
                isSign: true
            })
        }
        if (app.globalData.btn) {
            _this.getUserDetail()
            // _this.selCertificateFill()
            app.globalData.btn = false

        }
        _this.getUserisSignUp()
        this.handleGetDataList()
        this.setData({
            status: wx.getStorageSync('status'),
        })
    },
    // 获取报名信息和时间
    handleGetBkTime: function () {
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationBatch/selInformationBatchs',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            method: 'GET',
            success: (res) => {
                console.log(res);
                if (res.data.code == 0) {
                    this.data.timeOptions = {};
                    // _this.setData(res.data.data);
                    res.data.data.list.forEach(item => {
                        // 使用certificateName作为key，open_time作为value（根据需求，你也可以处理startTime和endTime来生成不同的时间格式或范围）
                        if (item.open_time.includes('，')) {
                            this.data.timeOptions[item.certificateName] = item.open_time.split('，');
                        } else {
                            // 如果open_time不是逗号分隔的，至少保证它是一个单元素数组
                            this.data.timeOptions[item.certificateName] = [item.open_time];
                        }
                    })
                    this.setData({
                        professionList: res.data.data.list.map(item => item.certificateName),
                    });
                    let bkindex=this.data.professionList[this.data.indexTime]
                    console.log(bkindex,'bk');
                    this.setData({
                        occupation:bkindex,
                        bkList:this.data.timeOptions[bkindex],
                    })
                } else {
                    app.showError(res.data.msg);
                    _this.setData({
                        isSignUp: false
                    });
                    return false;
                }
            }
        });
    },
    // 编辑证书
    handleGoEditBook: function (params) {
        // wx.setStorageSync('hcdatalist', {
        //     status: this.data.status,
        //     name: this.data.name,
        //     mobile: this.data.mobile,
        //     sex: this.data.indexSex,
        //     born: this.data.birthTime,
        //     education: this.data.indexEducation,
        //     major: this.data.major,
        //     personType: this.data.peType,
        //     certificateType: '0',
        //     idcardAddress: this.data.sfzaddress,
        //     idcardNumber: this.data.sfznumber,
        //     workUnit: this.data.workUnit,
        //     examTime: this.data.timedate,
        //     workTime: this.data.careerYears,
        //     declaredCareers: Number(this.data.indexNation),
        //     occupation:this.data.occupation,
        //     declaredLevel: this.data.indexDeclarationLevel,
        //     // declaredSubject: this.data.sbKemu,
        //     declaredSubject: this.data.itemsData.join(','),
        //     personPhoto: this.data.idFront,
        //     idcardPhoto: this.data.idReverse,
        //     graducationPhoto: this.data.recordCertificate,
        //     id: this.data.updateId
        // })
        wx.navigateTo({
            url: `/pages/addCertificate/addCertificate?datalist=${JSON.stringify(params.currentTarget.dataset.index)}`,
        })
    },
    // 编辑工作经历
    handleGoEditWork: function (params) {
        // wx.setStorageSync('hcdatalist', {
        //     status: this.data.status,
        //     name: this.data.name,
        //     mobile: this.data.mobile,
        //     sex: this.data.indexSex,
        //     born: this.data.birthTime,
        //     education: this.data.indexEducation,
        //     major: this.data.major,
        //     personType: this.data.peType,
        //     certificateType: '0',
        //     idcardAddress: this.data.sfzaddress,
        //     idcardNumber: this.data.sfznumber,
        //     workUnit: this.data.workUnit,
        //     examTime: this.data.timedate,
        //     workTime: this.data.careerYears,
        //     declaredCareers: Number(this.data.indexNation),
        //     occupation:this.data.occupation,
        //     declaredLevel: Number(this.data.indexDeclarationLevel),
        //     // declaredSubject: this.data.sbKemu,
        //     declaredSubject: this.data.itemsData.join(','),
        //     personPhoto: this.data.idFront,
        //     idcardPhoto: this.data.idReverse,
        //     graducationPhoto: this.data.recordCertificate,
        //     id: this.data.updateId
        // })
        wx.navigateTo({
            url: `/pages/addExperience/addExperience?datalist=${JSON.stringify(params.currentTarget.dataset.index)}`,
        })
    },
    /////////////////审核失败状态进入///////////////////////////
    handleGetDataList() {
        if (this.data.datalist.name) {
            wx.setStorageSync('status', 2)
            this.setData({
                status: 2
            })
            if (this.data.datalist.declaredLevel == '三级') {
                this.setData({
                    indexDeclarationLevel: 1
                })
            }
            if (this.data.datalist.declaredLevel == '四级') {
                this.setData({
                    indexDeclarationLevel: 2
                })
            }
            if (this.data.datalist.declaredLevel == '五级') {
                this.setData({
                    indexDeclarationLevel: 3
                })
            }
            this.setData({
                updateId: this.data.datalist.id,
                status: '2',
                name: this.data.datalist.name,
                mobile: this.data.datalist.mobile,
                indexSex: this.data.datalist.sex,
                birthTime: this.data.datalist.born,
                indexEducation: this.data.datalist.education,
                major: this.data.datalist.major,
                peType: this.data.datalist.personType,
                certificateType: '0',
                sfzaddress: this.data.datalist.idcardAddress,
                sfznumber: this.data.datalist.idcardNumber,
                workUnit: this.data.datalist.workUnit,
                timedate: this.data.datalist.examTime,
                careerYears: this.data.datalist.workTime,
                indexNation: this.data.datalist.declaredCareers,
                // indexDeclarationLevel: this.data.datalist.declaredLevel,
                // sbKemu: this.data.datalist.declaredSubject,
                itemsData: this.data.datalist.declaredSubject.split(','),
                imagesFront: this.data.datalist.personPhoto,
                imagesReverse: this.data.datalist.idcardPhoto,
                idFront: this.data.datalist.personPhoto,
                idReverse: this.data.datalist.idcardPhoto,
                imagesXueli: this.data.datalist.graducationPhoto,
                recordCertificate: this.data.datalist.graducationPhoto,
                bookList: this.data.datalist.certificateInfoConds,
                workjlList: this.data.datalist.experinceConds,
                reason: this.data.datalist.reason
            })
        } else {
            wx.setStorageSync('status', 0)
            this.setData({
                status: 0
            })
        }

    },
    // 多选框选择
    checkboxChange(e) {
        console.log('checkbox发生change事件，携带value值为：', e.detail.value)
        const items = this.data.items
        const values = e.detail.value
        for (let i = 0, lenI = items.length; i < lenI; ++i) {
            items[i].checked = false

            for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
                if (items[i].value === values[j]) {
                    items[i].checked = true
                    break
                }
            }
        }
        this.setData({
            items,
            itemsData: e.detail.value
        })
        console.log(this.data.itemsData, 'itemData');
    },
    // 单选框选择
    radioChange(e) {
        this.setData({
            peType: e.detail.value
        })
    },
    kemuradioChange(e) {
        this.setData({
            sbKemu: e.detail.value
        })

    },
    getDeclarationPeriod: function (e) {//累计从事申报职业年限
        this.setData({
            declarationPeriod: e.detail.value
        })
    },
    // 日历组件
    onDisplay() {
        this.setData({ show: true });
    },
    onClose() {
        this.setData({ show: false });
    },
    formatDate(date) {
        date = new Date(date);
        let month = `${date.getMonth() + 1}`
        let day = `${date.getDate()}`
        if (month.length < 2) {
            month = '0' + month
        }
        if (day.length < 2) {
            day = '0' + day
        }
        return `${date.getFullYear()}-${month}-${day}`;
    },
    onConfirm(event) {
        this.setData({
            show: false,
            timedate: this.formatDate(event.detail),
        });
    },
    ////////////////////日历组件
    // 查询报名信息
    handleGetUserInfo: function () {
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationImportUser/getUserInfo',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            method: 'GET',
            data: {
                declaredCareers:this.data.occupation
            },
            success: (res) => {
                this.setData({
                    bookList: res.data.data.certificateInfoVos,
                    workjlList: res.data.data.experinceVos,
                })
                console.log(this.data.itemsData);
                if (wx.getStorageSync('hcdatalist')) {
                    this.setData({
                        status: wx.getStorageSync('hcdatalist').status,
                        itemsData: wx.getStorageSync('hcdatalist').declaredSubject.split(','),
                        name: wx.getStorageSync('hcdatalist').name,
                        mobile: wx.getStorageSync('hcdatalist').mobile,
                        indexSex: wx.getStorageSync('hcdatalist').sex,
                        birthTime: wx.getStorageSync('hcdatalist').born,
                        indexEducation: wx.getStorageSync('hcdatalist').education,
                        major: wx.getStorageSync('hcdatalist').major,
                        peType: wx.getStorageSync('hcdatalist').personType,
                        certificateType: '0',
                        sfzaddress: wx.getStorageSync('hcdatalist').idcardAddress,
                        sfznumber: wx.getStorageSync('hcdatalist').idcardNumber,
                        workUnit: wx.getStorageSync('hcdatalist').workUnit,
                        timedate: wx.getStorageSync('hcdatalist').examTime,
                        careerYears: wx.getStorageSync('hcdatalist').workTime,
                        indexNation: Number(wx.getStorageSync('hcdatalist').declaredCareers),
                        occupation:wx.getStorageSync('hcdatalist').occupation,
                        indexDeclarationLevel: Number(wx.getStorageSync('hcdatalist').declaredLevel),
                        // sbKemu: wx.getStorageSync('hcdatalist').declaredSubject,
                        itemsData: wx.getStorageSync('hcdatalist').declaredSubject.split(','),
                        idFront: wx.getStorageSync('hcdatalist').personPhoto,
                        idReverse: wx.getStorageSync('hcdatalist').idcardPhoto,
                        imagesFront: wx.getStorageSync('hcdatalist').personPhoto,
                        imagesReverse: wx.getStorageSync('hcdatalist').idcardPhoto,
                        recordCertificate: wx.getStorageSync('hcdatalist').graducationPhoto,
                        imagesXueli: wx.getStorageSync('hcdatalist').graducationPhoto,
                        updateId: wx.getStorageSync('hcdatalist').id
                    })
                    return false;
                }
                if (res.data.data.declaredLevel == '三级') {
                    this.setData({
                        indexDeclarationLevel: 1
                    })
                }
                if (res.data.data.declaredLevel == '四级') {
                    this.setData({
                        indexDeclarationLevel: 2
                    })
                }
                if (res.data.data.declaredLevel == '五级') {
                    this.setData({
                        indexDeclarationLevel: 3
                    })
                }
            }
        });
        // 获取申报职业和开班时间
    },
    //获取证书考试信息
    getList: function () {
        var _this = this;
        var requestHead = {
            'content-type': 'application/json'
        }
        wx.request({
            url: siteinfo.selCertificateDetail,
            header: requestHead,
            data: {},
            success: function (res) {
                // console.log(res);
                if (res.data.code === 0 || res.data.code === '0') {
                    _this.setData(res.data.data);
                    wx.setStorageSync("certificateInfo", res.data.data);
                } else {
                    app.showError(res.data.msg);
                    _this.setData({
                        isSignUp: false
                    });
                    return false;
                }
            }
        });
    },
    // 参考页面
    handleReference: function () {
        wx.navigateTo({
            url: '/pages/reTemplate/reTemplate'
        })
    },
    // 跳转到添加工作经历页面
    handleAddExperience: function () {
        wx.setStorageSync('hcdatalist', {
            status: this.data.status,
            name: this.data.name,
            mobile: this.data.mobile,
            sex: this.data.indexSex,
            born: this.data.birthTime,
            education: this.data.indexEducation,
            major: this.data.major,
            personType: this.data.peType,
            certificateType: '0',
            idcardAddress: this.data.sfzaddress,
            idcardNumber: this.data.sfznumber,
            workUnit: this.data.workUnit,
            examTime: this.data.timedate,
            workTime: this.data.careerYears,
            declaredCareers: Number(this.data.indexNation),
            occupation:this.data.occupation,
            declaredLevel: Number(this.data.indexDeclarationLevel),
            // declaredSubject: this.data.sbKemu,
            declaredSubject: this.data.itemsData.join(','),
            personPhoto: this.data.idFront,
            idcardPhoto: this.data.idReverse,
            graducationPhoto: this.data.recordCertificate,
            id: this.data.updateId
        })
        wx.navigateTo({
            url: '/pages/addExperience/addExperience'
        })
    },
    // 跳转到添加证书
    handleAddBook: function () {
        // if(){

        // }
        wx.setStorageSync('hcdatalist', {
            status: this.data.status,
            name: this.data.name,
            mobile: this.data.mobile,
            sex: this.data.indexSex,
            born: this.data.birthTime,
            education: this.data.indexEducation,
            major: this.data.major,
            personType: this.data.peType,
            certificateType: '0',
            idcardAddress: this.data.sfzaddress,
            idcardNumber: this.data.sfznumber,
            workUnit: this.data.workUnit,
            examTime: this.data.timedate,
            workTime: this.data.careerYears,
            declaredCareers: Number(this.data.indexNation),
            occupation:this.data.occupation,
            declaredLevel: Number(this.data.indexDeclarationLevel),
            // declaredSubject: this.data.sbKemu,
            declaredSubject: this.data.itemsData.join(','),
            personPhoto: this.data.idFront,
            idcardPhoto: this.data.idReverse,
            graducationPhoto: this.data.recordCertificate,
            id: this.data.updateId
        })
        wx.navigateTo({
            url: '/pages/addCertificate/addCertificate'
        })
    },
    // 获取职业年限
    getCareerYears: function (e) {
        var value = e.detail.value;
        this.setData({
            careerYears: value
        });
    },
    //获取姓名
    getName: function (e) {
        var value = e.detail.value;
        this.setData({
            name: value
        });
    },
    // 获取身份证地址
    getSfzaddress: function (e) {
        var value = e.detail.value;
        this.setData({
            sfzaddress: value
        });
    },
    // 获取身份证地址
    getSfznumber: function (e) {
        var value = e.detail.value;
        this.setData({
            sfznumber: value
        });
    },
    // //获取手机号
    // getIPhone: function (e) {
    //     var value = e.detail.value;
    //     this.setData({
    //         mobile: value
    //     });
    // },
    // 获取工作单位
    getWorkUnit: function (e) {
        var value = e.detail.value;
        this.setData({
            workUnit: value
        });
    },
    //选择性别
    sexChange: function (e) {
        this.setData({
            indexSex: e.detail.value
        })
    },
    //选择开班时间
    timeChange: function (e) {
        console.log(e.detail.value);
        this.setData({
            timedate: this.data.bkList[e.detail.value],
            indexTime: e.detail.value
        })
        console.log(this.data.timedate);
    },
    //选择出生年月
    bindDateChange: function (e) {
        this.setData({
            birthTime: e.detail.value
        })
    },
    //参加工作时间
    bindDateChanges: function (e) {
        this.setData({
            workDate: e.detail.value
        })
    },

    //申报认定等级
    declarationLevelChange: function (e) {
        var _this = this
        _this.setData({
            indexDeclarationLevel: e.detail.value,
            declarationLevel: _this.data.gradeList[e.detail.value]
        })
    },
    //申报职业
    workChange: function (e) {
        var _this = this
        const index = e.detail.value;
        console.log(index,'22233');
        const profession = this.data.professionList[index];
        _this.setData({
            bkList: _this.data.timeOptions[profession] || [],
            indexNation: e.detail.value,
            occupation: _this.data.professionList[e.detail.value]
        })
    },
    //申报认定职业
    professionChange: function (e) {
        var _this = this
        _this.setData({
            indexProfession: e.detail.value,
            profession: _this.data.professionList[e.detail.value]
        })
    },
    //选择学历
    educationChange: function (e) {
        var _this = this
        _this.setData({
            indexEducation: e.detail.value,
            education: _this.data.educationList[e.detail.value]
        })
    },
    //获取专业
    getMajor: function (e) {
        this.setData({
            major: e.detail.value
        });
    },
    //获取身份证号
    getIdNumber: function (e) {
        this.setData({
            idNumber: e.detail.value
        })
    },
    //获取毕业证书编号
    getCertificateNo: function (e) {
        this.setData({
            certificateNo: e.detail.value
        });
    },
    //工作单位名称
    getOrgName: function (e) {
        this.setData({
            orgName: e.detail.value
        })
    },
    //单位联系电话
    getUnitPhone: function (e) {
        this.setData({
            unitPhone: e.detail.value
        })
    },
    //岗位名称
    getPostName: function (e) {
        this.setData({
            postName: e.detail.value
        })
    },
    getClassLevel: function (e) {
        this.setData({
            classLevel: e.detail.value
        })
    },
    //获取原证书编号
    getLevelNum: function (e) {
        this.setData({
            levelNum: e.detail.value
        })
    },
    
    // //获取手机号
    // getMobile: function (e) {
    //     this.setData({
    //         mobile: e.detail.value
    //     })
    // },
    //获取邮寄地址
    getAddress: function (e) {
        this.setData({
            address: e.detail.value
        })
    },
    onChange(event) {
        this.setData({
            itemsData: event.detail,
        });
    },
    //获取学习、工作经历
    //  getExperience:function(e){
    //    this.setData({
    //      experience:e.detail.value
    //    })
    // console.log(this.data.experience)
    //  },
    //选择省市区
    bindRegionChange: function (e) {
        //console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            region: e.detail.value
        })
    },
    //认定科目
    // checkboxChange: function (e) {
    //     console.log(e.detail.value)
    //     this.setData({
    //         kemu: e.detail.value
    //     })
    // },
    //选择考生类型
    changeType: function (e) {
        var _this = this
        _this.setData({
            typeIndex: e.detail.value,
            type: _this.data.typeList[e.detail.value].id
        })
    },
    getUserisSignUp: function () {
        app._getLogin(siteinfo.selUserIsSignUp, { cbatch: wx.getStorageSync('certificateInfo').authentication_id }, function (res) {
            if (res.data.isSignUp) {
                wx.navigateTo({
                    url: '/pages/signExamine/signExamine?id=' + res.data.signUpId,
                })
            }
        })
    },
    //获取用户照片
    getUserDetail: function () {
        var _this = this;
        app._getLogin(siteinfo.selUserDetail, {}, function (result) {
            if (result.data.headPortrait != '' && result.data.headPortrait != null) {
                _this.setData({
                    images: result.data.headPortrait
                });
            }
            _this.setData({
                photo: result.data.headPortrait,
            });
        });

    },
    chooseImageFront(e) { //身份证正面
        wx.setStorageSync('hcdatalist', {
            status: this.data.status,
            name: this.data.name,
            mobile: this.data.mobile,
            sex: this.data.indexSex,
            born: this.data.birthTime,
            education: this.data.indexEducation,
            major: this.data.major,
            personType: this.data.peType,
            certificateType: '0',
            idcardAddress: this.data.sfzaddress,
            idcardNumber: this.data.sfznumber,
            workUnit: this.data.workUnit,
            examTime: this.data.timedate,
            workTime: this.data.careerYears,
            declaredCareers: Number(this.data.indexNation),
            occupation: this.data.occupation,
            declaredLevel: this.data.indexDeclarationLevel,
            // declaredSubject: this.data.sbKemu,
            declaredSubject: this.data.itemsData.join(','),
            personPhoto: this.data.idFront,
            idcardPhoto: this.data.idReverse,
            graducationPhoto: this.data.recordCertificate,
            id: this.data.updateId
        })
        var _this = this
        wx.chooseImage({
            sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
            sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
            success: res => {
                if (res.tempFiles[0].size < 5242880) {
                    wx.getImageInfo({
                        src: res.tempFilePaths[0],
                        success(result) {
                            const tempFilePaths = res.tempFilePaths
                            app._uploadFile(siteinfo.fileImprot,
                                res.tempFiles[0].path,
                                'file', {
                                name: res.tempFiles[0].name
                            },
                                function (res1) {
                                    _this.setData({
                                        idFront: res1.data,
                                        imagesFront: tempFilePaths,
                                    })
                                    // 获取存储的对象
                                    let storedObject = wx.getStorageSync('hcdatalist');
                                    // 确保对象已被正确获取
                                    if (storedObject) {
                                        // 修改对象的属性值
                                        storedObject.personPhoto = _this.data.idFront;
                                        // 存储修改后的对象回storage
                                        wx.setStorageSync('hcdatalist', storedObject);
                                    } else {
                                        console.log('对象未找到');
                                    }
                                    return false;
                                })
                        }
                    })
                } else {
                    app.showError('寸照应小于5M！')
                }
            }
        })
    },
    chooseImageReverse(e) { //身份证反面
        wx.setStorageSync('hcdatalist', {
            status: this.data.status,
            name: this.data.name,
            mobile: this.data.mobile,
            sex: this.data.indexSex,
            born: this.data.birthTime,
            education: this.data.indexEducation,
            major: this.data.major,
            personType: this.data.peType,
            certificateType: '0',
            idcardAddress: this.data.sfzaddress,
            idcardNumber: this.data.sfznumber,
            workUnit: this.data.workUnit,
            examTime: this.data.timedate,
            workTime: this.data.careerYears,
            declaredCareers: Number(this.data.indexNation),
            occupation:this.data.occupation,
            declaredLevel: this.data.indexDeclarationLevel,
            // declaredSubject: this.data.sbKemu,
            declaredSubject: this.data.itemsData.join(','),
            personPhoto: this.data.idFront,
            idcardPhoto: this.data.idReverse,
            graducationPhoto: this.data.recordCertificate,
            id: this.data.updateId
        })
        var _this = this
        wx.chooseImage({
            sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
            sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
            success: res => {
                if (res.tempFiles[0].size < 5242880) {
                    wx.getImageInfo({
                        src: res.tempFilePaths[0],
                        success(result) {
                            const tempFilePaths = res.tempFilePaths
                            app._uploadFile(siteinfo.fileImprot,
                                res.tempFiles[0].path,
                                'file', {
                                name: res.tempFiles[0].name
                            },
                                function (res1) {
                                    _this.setData({
                                        idReverse: res1.data,
                                        imagesReverse: tempFilePaths,
                                    })
                                    // 获取存储的对象
                                    let storedObject = wx.getStorageSync('hcdatalist');
                                    // 确保对象已被正确获取
                                    if (storedObject) {
                                        // 修改对象的属性值
                                        storedObject.idcardPhoto = _this.data.idReverse;
                                        // 存储修改后的对象回storage
                                        wx.setStorageSync('hcdatalist', storedObject);
                                    } else {
                                        console.log('对象未找到');
                                    }
                                    return false;
                                })
                        }
                    })
                } else {
                    app.showError('寸照应小于5M！')
                }
            }
        })
    },
    chooseImageXueli(e) { //学历证书
        wx.setStorageSync('hcdatalist', {
            status: this.data.status,
            name: this.data.name,
            mobile: this.data.mobile,
            sex: this.data.indexSex,
            born: this.data.birthTime,
            education: this.data.indexEducation,
            major: this.data.major,
            personType: this.data.peType,
            certificateType: '0',
            idcardAddress: this.data.sfzaddress,
            idcardNumber: this.data.sfznumber,
            workUnit: this.data.workUnit,
            examTime: this.data.timedate,
            workTime: this.data.careerYears,
            declaredCareers: Number(this.data.indexNation),
            occupation:this.data.occupation,
            declaredLevel: this.data.indexDeclarationLevel,
            // declaredSubject: this.data.sbKemu,
            declaredSubject: this.data.itemsData.join(','),
            personPhoto: this.data.idFront,
            idcardPhoto: this.data.idReverse,
            graducationPhoto: this.data.recordCertificate,
            id: this.data.updateId
        })
        var _this = this
        wx.chooseImage({
            sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
            sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
            success: res => {
                console.log(res);
                if (res.tempFiles[0].size < 5242880) {
                    wx.getImageInfo({
                        src: res.tempFilePaths[0],
                        success(result) {
                            const tempFilePaths = res.tempFilePaths
                            app._uploadFile(siteinfo.fileImprot,
                                res.tempFiles[0].path,
                                'file', {
                                name: res.tempFiles[0].name
                            },
                                function (res1) {
                                    _this.setData({
                                        recordCertificate: res1.data,
                                        imagesXueli: tempFilePaths,
                                    })
                                    // 获取存储的对象
                                    let storedObject = wx.getStorageSync('hcdatalist');
                                    // 确保对象已被正确获取
                                    if (storedObject) {
                                        // 修改对象的属性值
                                        storedObject.graducationPhoto = _this.data.recordCertificate;
                                        // 存储修改后的对象回storage
                                        wx.setStorageSync('hcdatalist', storedObject);
                                    } else {
                                        console.log('对象未找到');
                                    }
                                    return false;
                                })
                        }
                    })
                } else {
                    app.showError('寸照应小于5M！')
                }
            }
        })
    },


    // 重新提交
    handleReBtnSubMit: function (check) {
        if (this.data.name == '') {
            app.showError('请输入姓名!')
            return false;
        }

        // if (this.data.mobile == '') {
        //     app.showError('请输入手机号!')
        //     return false;
        // }
        if (this.data.indexSex == '') {
            app.showError('请选择性别!')
            return false;
        }
        if (this.data.birthTime == '') {
            app.showError('请选择出生日期!')
            return false;
        }
        if (this.data.indexEducation == 0) {
            app.showError('请选择学历!')
            return false;
        }
        if (this.data.major == '') {
            app.showError('请输入所学专业!')
            return false;
        }
        if (this.data.peType == 10000) {
            app.showError('请选择人员类别!')
            return false;
        }
        if (this.data.sfzaddress == '') {
            app.showError('请输入身份证地址!')
            return false;
        }
        if (this.data.sfznumber == '') {
            app.showError('请输入身份证号!')
            return false;
        }

        if (this.data.indexDeclarationLevel == 0) {
            app.showError('请选择申报认定等级!')
            return false;
        }
        // if (this.data.sbKemu == 10000) {
        //     app.showError('请选择申报科目!')
        //     return false;
        // }
        if (this.data.itemsData == []) {
            app.showError('请选择申报科目!')
            return false;
        }
        if (this.data.imagesFront == '/image/addPic.png') {
            app.showError('请上传2寸白底寸照!')
            return false;
        }
        if (this.data.imagesReverse == '/image/addPic.png') {
            app.showError('请上传身份证正反面复印件!')
            return false;
        }
        if (this.data.imagesXueli == '/image/addPic.png') {
            app.showError('请上传毕业证!')
            return false;
        }

        if (this.data.indexDeclarationLevel == 1) {
            this.setData({
                indexDeclarationLevel: '三级'
            })
        }
        if (this.data.indexDeclarationLevel == 2) {
            this.setData({
                indexDeclarationLevel: '四级'
            })
        }
        if (this.data.indexDeclarationLevel == 3) {
            this.setData({
                indexDeclarationLevel: '五级'
            })
        }
        console.log(this.data.bookList);
        console.log(this.data.workList, 'submit');
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationImportUser/updateUserInfo',
            method: 'POST',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            data: {
                name: this.data.name,
                mobile: this.data.mobile,
                sex: this.data.indexSex,
                born: this.data.birthTime,
                education: this.data.indexEducation,
                major: this.data.major,
                personType: this.data.peType,
                certificateType: '0',
                idcardAddress: this.data.sfzaddress,
                idcardNumber: this.data.sfznumber,
                workUnit: this.data.workUnit,
                examTime: this.data.timedate,
                workTime: this.data.careerYears,
                declaredCareers: Number(this.data.indexNation),
                declaredLevel: this.data.indexDeclarationLevel,
                declaredSubject: this.data.itemsData.join(','),
                personPhoto: this.data.idFront,
                idcardPhoto: this.data.idReverse,
                graducationPhoto: this.data.recordCertificate,
                certificateInfoConds: this.data.bookList,
                experinceConds: this.data.workjlList,
                id: this.data.updateId
            },
            success: function (res) {
                if (res.data.code == '0') {
                    wx.removeStorageSync('hcdatalist')
                    wx.redirectTo({
                        url: '/pages/entryCompleted/entryCompleted'
                    })
                } else {
                    app.showError(res.data.msg)
                    return false;
                }
            }
        });
    },
    handleBtnSubMit: function () {
        if (this.data.indexDeclarationLevel == 1) {
            this.setData({
                indexDeclarationLevel: '三级'
            })
        }
        if (this.data.indexDeclarationLevel == 2) {
            this.setData({
                indexDeclarationLevel: '四级'
            })
        }
        if (this.data.indexDeclarationLevel == 3) {
            this.setData({
                indexDeclarationLevel: '五级'
            })
        }
        console.log(this.data.indexDeclarationLevel);
        if (this.data.name == '') {
            app.showError('请输入姓名!')
            return false;
        }
        // if (this.data.mobile == '') {
        //     app.showError('请输入手机号!')
        //     return false;
        // }
        // if (this.data.mobile == '') {
        //     app.showError('请输入手机号!')
        //     return false;
        // }
        if (this.data.indexSex == '') {
            app.showError('请选择性别!')
            return false;
        }
        if (this.data.birthTime == '') {
            app.showError('请选择出生日期!')
            return false;
        }
        if (this.data.indexEducation == 0) {
            app.showError('请选择学历!')
            return false;
        }
        if (this.data.major == '') {
            app.showError('请输入所学专业!')
            return false;
        }
        if (this.data.peType == 10000) {
            app.showError('请选择人员类别!')
            return false;
        }
        if (this.data.sfzaddress == '') {
            app.showError('请输入身份证地址!')
            return false;
        }
        if (this.data.sfznumber == '') {
            app.showError('请输入身份证号!')
            return false;
        }

        if (this.data.timedate == '请选择报考时间' || this.data.timedate == '') {
            app.showError('请选择报考时间!')
            return false;
        }
        if (this.data.indexDeclarationLevel == 0) {
            app.showError('请选择申报认定等级!')
            return false;
        }
        // if (this.data.sbKemu == 10000) {
        //     app.showError('请选择申报科目!')
        //     return false;
        // }
        if (this.data.itemsData == []) {
            app.showError('请选择申报科目!')
            return false;
        }
        if (this.data.imagesFront == '/image/addPic.png') {
            app.showError('请上传2寸白底寸照!')
            return false;
        }
        if (this.data.imagesReverse == '/image/addPic.png') {
            app.showError('请上传身份证正反面复印件!')
            return false;
        }
        if (this.data.imagesXueli == '/image/addPic.png') {
            app.showError('请上传毕业证!')
            return false;
        }
        console.log(this.data.declarationLevel);
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationImportUser/saveUserInfo',
            method: 'POST',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            data: {
                name: this.data.name,
                mobile: this.data.mobile,
                sex: this.data.indexSex,
                born: this.data.birthTime,
                education: this.data.indexEducation,
                major: this.data.major,
                personType: this.data.peType,
                certificateType: '0',
                idcardAddress: this.data.sfzaddress,
                idcardNumber: this.data.sfznumber,
                workUnit: this.data.workUnit,
                examTime: this.data.timedate,
                workTime: this.data.careerYears,
                declaredCareers: Number(this.data.indexNation),
                declaredLevel: this.data.indexDeclarationLevel,
                // declaredSubject: this.data.sbKemu,
                declaredSubject: this.data.itemsData.join(','),
                personPhoto: this.data.idFront,
                idcardPhoto: this.data.idReverse,
                graducationPhoto: this.data.recordCertificate,
                certificateInfoConds: this.data.bookList,
                experinceConds: this.data.workjlList,
            },
            success: function (res) {
                console.log(res);
                if (res.data.code == '0') {
                    wx.removeStorageSync('hcdatalist')
                    wx.redirectTo({
                        url: '/pages/entryCompleted/entryCompleted'
                    })
                } else {
                    app.showError(res.data.msg)
                    return false;
                }
            }
        });
    },

    //选择要上传的上传文件
    chooseFile() {
        if (wx.getStorageSync('hcdatalist')) {
            this.setData({
                status: wx.getStorageSync('hcdatalist').status,
                name: wx.getStorageSync('hcdatalist').name,
                mobile: wx.getStorageSync('hcdatalist').mobile,
                indexSex: wx.getStorageSync('hcdatalist').sex,
                birthTime: wx.getStorageSync('hcdatalist').born,
                indexEducation: wx.getStorageSync('hcdatalist').education,
                major: wx.getStorageSync('hcdatalist').major,
                peType: wx.getStorageSync('hcdatalist').personType,
                certificateType: '0',
                sfzaddress: wx.getStorageSync('hcdatalist').idcardAddress,
                sfznumber: wx.getStorageSync('hcdatalist').idcardNumber,
                workUnit: wx.getStorageSync('hcdatalist').workUnit,
                timedate: wx.getStorageSync('hcdatalist').examTime,
                careerYears: wx.getStorageSync('hcdatalist').workTime,
                indexNation: Number(wx.getStorageSync('hcdatalist').declaredCareers),
                occupation:wx.getStorageSync('hcdatalist').occupation,
                indexDeclarationLevel: Number(wx.getStorageSync('hcdatalist').declaredLevel),
                // sbKemu: wx.getStorageSync('hcdatalist').declaredSubject,
                itemsData: wx.getStorageSync('hcdatalist').declaredSubject.split(','),
                idFront: wx.getStorageSync('hcdatalist').personPhoto,
                idReverse: wx.getStorageSync('hcdatalist').idcardPhoto,
                imagesFront: wx.getStorageSync('hcdatalist').personPhoto,
                imagesReverse: wx.getStorageSync('hcdatalist').idcardPhoto,
                recordCertificate: wx.getStorageSync('hcdatalist').graducationPhoto,
                imagesXueli: wx.getStorageSync('hcdatalist').graducationPhoto,
                updateId: wx.getStorageSync('hcdatalist').id
            })
        }
        let _this = this;
        wx.chooseMessageFile({
            count: 1,
            type: 'file',
            success(res) {
                // console.log(" :res", res.tempFiles[0])
                _this.setData({
                    fileName: res.tempFiles[0].name,
                })
                app._uploadFile(siteinfo.fileImprot,
                    res.tempFiles[0].path,
                    'file', {
                    name: res.tempFiles[0].name
                },
                    function (res) {
                        //  console.log("res", res.data)
                        _this.setData({
                            fileUrl: res.data,
                        })
                    }
                )
            }
        })
    },
    signName: function () {
        wx.navigateTo({
            url: 'signName',
        })
    },
    onPullDownRefresh: function () {
        this.handleGetUserInfo()
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})